global root_path "/Volumes/Workgroup/Lab/Lab-heimb/Montenovo/Volunteering Paper/Data"

clear all
set maxvar 32767

cd "$root_path/02_ready_for_PSIDclean"

use individ_family_2001.dta, clear

cd "$root_path/03_ready_for_TAXSIM"
**HH ID
rename ER17002 family_id

gen unique_id_crossys=(ER30001*1000) + ER30002

gen sequence_num=ER33602

sort family_id sequence_num

rename ER30000 release_number
rename ER30001 interview_number_1986
rename ER30002 person_number

//order ER30001 ER30002 sequence_num unique_id_crossys ID_unique_year ER32000 ER17002  ER17011 ER17013 ER17014 ER17015 ER17016  ER20089 ER20097 ER20369 ER20088 ER20096
//browse ER30001 ER30002 sequence_num ID_unique_id_crossys ID_unique_year ER32000 ER17002  ER17011 ER17013 ER17014 ER17015 ER17016  ER20089 ER20097 ER20369 ER20088 ER20096

** Race

* wife
gen white_w=0
replace white_w=1 if ER19897==1 & ER19898==0 & ER19899==0 & ER19800==0

gen black_w=0
replace black_w=1 if ER19897==2 & ER19898==0 & ER19899==0 & ER19800==0

gen native_amer_w=0
replace native_amer_w=1 if ER19897==3 & ER19898==0 & ER19899==0 & ER19800==0

gen asian_w=0
replace asian_w=1 if ER19897==4 & ER19898==0 & ER19899==0 & ER19800==0

*gen latino_w=0
*replace latino_w=1 if ER19897==5 & ER19898==0 & ER19899==0 & ER19800==0

gen other_w=0
replace other_w=1 if (ER19897>=5)
replace other_w=1 if ER19898!=0 | ER19899!=0 | ER19800!=0

gen any_race_w=white_w+black_w+native_amer_w+asian_w+other_w
sum any_race_w

*  3,721 have no recorded race in OUR data
*  3,524: no wife present
*  3,721-3,524 are mixed race so we did not code them yet

* husband
gen white_h=0
replace white_h=1 if ER19989==1 & ER19990==0 & ER19991==0 & ER19992==0

gen black_h=0
replace black_h=1 if ER19989==2 & ER19990==0 & ER19991==0 & ER19992==0

gen native_amer_h=0
replace native_amer_h=1 if ER19989==3 & ER19990==0 & ER19991==0 & ER19992==0

gen asian_h=0
replace asian_h=1 if ER19989==4 & ER19990==0 & ER19991==0 & ER19992==0

*gen latino_h=0
*replace latino_h=1 if ER19989==5 & ER19990==0 & ER19991==0 & ER19992==0

gen other_h=0
replace other_h=1 if ER19989>=5
replace other_h=1 if ER19990!=0 | ER19991!=0 | ER19992!=0

gen any_race_h=white_h+black_h+native_amer_h+asian_h+other_h
sum any_race_h

*if it does not work, use white black native_amer asian to build other

* make sure all the observations have one 1 among all the race variables

*  7,524 have recorded race in OUR data
*  298: are mixed race so we did not code them yet

** State of residence.
rename ER17004 state_residence

** RAW FIELDS.
** Marriage stuff.
rename ER17024 marital_status_head
rename ER17014 sex_head

gen married=0
replace married=1 if marital_status_head==1

keep if (sequence_num==1 & married==0) | (sequence_num==1 & married==1) | (sequence_num==2 & married==1)


** Children.
rename ER17016 children
** Ages.
rename ER17013 age_head
rename ER17015 age_wife

sort unique_id_crossys

order interview_number_1986 marital_status_head unique_id_crossys sequence_num white_w black_w    white_h black_h    ER32000 age_head age_wife

order interview_number_1986 family_id marital_status_head unique_id_crossys sequence_num white_w black_w   white_h black_h    ER32000 age_head age_wife



** GENERATED FIELDS.
rename ER20420 farm_inc_head_gen
rename ER18634 rent_inc_head
rename ER18635 rent_inc_head_unit
*rename ???? rent_inc_wife
*rename ???? rent_inc_wife_unit
rename ER20423 unincorp_assetpt_inc_head_gen
rename ER20437 gardening_inc_head_gen
rename ER18863 alimony_inc_head
rename ER18864 alimony_inc_head_unit
rename ER20444 unincorp_assetpt_inc_wife_gen
rename ER18666 interest_inc_head
rename ER18667 interest_inc_head_unit
rename ER18982 interest_inc_wife
rename ER18983 interest_inc_wife_unit

rename ER20456 taxable_inc_hh_gen
rename ER20447 labor_inc_wife_gen

rename ER18650 dividend_inc_head
rename ER18651 dividend_inc_head_unit
rename ER18966 dividend_inc_wife
rename ER18967 dividend_inc_wife_unit
rename ER20443 labor_inc_head_gen

rename ER19183 alimony_given

rename ER18766 nonva_retire_inc_head
rename ER18767 nonva_retire_inc_head_unit
rename ER19095 retire_annuities_inc_wife
rename ER19096 retire_annuities_inc_wife_unit

rename ER20455 socsec_inc_fu

rename ER18715 ssi_inc_head
rename ER18716 ssi_inc_head_unit
rename ER19031 ssi_inc_wife
rename ER19032 ssi_inc_wife_unit
rename ER18750 vapension_inc_head
rename ER18751 vapension_inc_head_unit
rename ER18831 workerscomp_inc_head
rename ER18832 workerscomp_inc_head_unit
rename ER18950 workerscomp_inc_wife
rename ER18951 workerscomp_inc_wife_unit

rename ER18698 tanf_inc_head
rename ER18699 tanf_inc_head_unit
rename ER19047 tanf_inc_wife
rename ER19048 tanf_inc_wife_unit
rename ER18731 otherwelfare_inc_head
rename ER18732 otherwelfare_inc_head_unit
rename ER19079 otherwelfare_inc_wife
rename ER19080 otherwelfare_inc_wife_unit
rename ER18847 childsupport_inc_head
rename ER18848 childsupport_inc_head_unit
rename ER19063 childsupport_inc_wife
rename ER19064 childsupport_inc_wife_unit

** Rent.
rename ER17074 rent_amount
rename ER17075  rent_amount_unit

** Taxes.
rename ER17046 property_tax_annual

** Deductions.
rename ER19161 whether_itemized
rename ER19162 itemized_charitable
rename ER19167 itemized_medical

** Child care.
rename ER18362 childcare_expense

** Unemployment.
rename ER18815 unemployment_inc_head
rename ER18816 unemployment_inc_head_unit
rename ER18934 unemployment_inc_wife
rename ER18935 unemployment_inc_wife_unit

** Mortgage payments.
rename ER17052 mortgage1_principle_remaining
rename ER17056 mortgage1_interest_rate_wholenum
rename ER17057 mortgage1_interest_rate_fraction

** Food consumption.
rename ER18417 food_stamps
rename ER18418 food_stamps_unit
rename ER18421 food_homestamps
rename ER18422 food_homestamps_unit
rename ER18425 food_deliveredstamps
rename ER18426 food_deliveredstamps_unit
rename ER18428 food_awaystamps
rename ER18429 food_awaystamps_unit
rename ER18431 food_home
rename ER18432 food_home_unit
rename ER18435 food_delivered
rename ER18436 food_delivered_unit
rename ER18438 food_away
rename ER18439 food_away_unit

rename ER17805 hr_wage_spouse
rename ER17235 hr_wage_hd
rename ER18561 tot_wage_hd
rename ER18930 tot_wage_spouse
rename ER20399 tot_hs_worked_head
rename ER20410 tot_hs_worked_spouse

rename ER20038 religion_hd
rename ER19945 religion_spouse
rename ER20377C rural

rename ER18814 whether_unemployed_head
rename ER18933 whether_unemployed_spouse

drop ER*

save fam2001er-small.dta, replace 

